#encoding: utf-8
from flask import jsonify
class ResponseCode(object):
    ok = 1
    paramError = 0
    serverError = -1
    unauthError = 2
    otherError = 3

def restful_result(code, message, data):
    return jsonify({"code":code, "message":message, "data":data or {}})

def success(message="操作成功", data=None):
    return restful_result(code=ResponseCode.ok, message=message, data=data)

def params_error(message=""):
    return restful_result(code=ResponseCode.paramError, message=message or '操作失败', data=None)

def unauth_error(message=""):
    return restful_result(code=ResponseCode.unauthError, message=message or '授权错误', data=None)

def server_error(message=""):
    return restful_result(code=ResponseCode.serverError, message=message or '服务器内部错误', data=None)


